﻿<?xml version="1.0" encoding="utf-8" ?>
<!--namespace必须用否者就报错（读取配置文件报：未将对象引用设置到对象的实例）-->
<sqlMap namespace="" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <statements>
    <!-- Insert-->
    <!-- Org-->
    <insert id="InsertOrg" parameterClass="hashtable">
      insert into [SYS_Dept]  values(#DeptID#,#DeptCode#,#DeptName#,#Path#,#Manager#,#Remark#,#ParentId#,
      #Sequence#,#LastUpdateUserName#,#LastUpdateUserFullName#,#LastUpdateTime#,#CreateUserName#,#CreateUserFullName#,#CreateDateTime#)
    </insert>
    
    <!-- User-->
    <insert id="InsertUser" parameterClass="hashtable">
      insert into [SYS_User]  values(#UserName#,#FullName#,#UserNickName#,#Password#,#UserNO#,#UserType#,#DeptID#,#Gender#,#Birthplace#,#National#
      ,#IDCard#,#Birthday#,#Email#,#EmailBacker#,#OfficePhone#,#HomePhone#,#MobilePhone#,#QQ#,#MSN#,#Sequence#,#AccountState#,#LastUpdateUserName#
      ,#LastUpdateUserFullName#,#LastUpdateTime#,#CreateUserName#,#CreateUserFullName#,#CreateDateTime#)
    </insert>
    
    <!-- Delete-->
    <!--  User-->
    <delete id="DeleteUser" parameterClass="string" resultClass="int">
      DELETE FROM SYS_User
      WHERE [UserName]= #UserName#
    </delete>
    
    
    <!-- Update-->
    <!-- User-->
    <update id="SetPasswordByUserName" parameterClass="hashtable" resultClass="int">
      update SYS_User set Password=#password# where UserName=#username#
    </update>
    
    <!-- Org-->
    <update id="UpdateOrg" parameterClass="hashtable" resultClass="int">
      UPDATE [SYS_Dept]
      SET [DeptCode]=#DeptCode#
      ,[DeptName]=#DeptName#
      ,[ParentId]=#ParentId#
      ,[Path]=#Path#
      ,[Manager]=#Manager#
      ,[Remark]=#Remark#
      ,[Sequence]=#Sequence#
      ,[LastUpdateUserName]=#LastUpdateUserName#
      ,[LastUpdateUserFullName]=#LastUpdateUserFullName#
      ,[LastUpdateTime]=#LastUpdateTime#
      ,[CreateUserName]=#CreateUserName#
      ,[CreateUserFullName]=#CreateUserFullName#
      ,[CreateDateTime]=#CreateDateTime#
      WHERE [DeptID]=#DeptID#
    </update>
    <!-- User-->
    <update id="UpdateUser" parameterClass="hashtable" resultClass="int">
      UPDATE [SYS_User]
      SET [FullName]=#FullName#
      ,[UserNickName]=#UserNickName#
      ,[Password]=#Password#
      ,[UserNO]=#UserNO#
      ,[UserType]=#UserType#
      ,[DeptID]=#DeptID#
      ,[Gender]=#Gender#
      ,[Birthplace]=#Birthplace#
      ,[National]=#National#
      ,[IDCard]=#IDCard#
      ,[Birthday]=#Birthday#
      ,[Email]=#Email#
      ,[EmailBacker]=#EmailBacker#
      ,[OfficePhone]=#OfficePhone#
      ,[HomePhone]=#HomePhone#
      ,[MobilePhone]=#MobilePhone#
      ,[QQ]=#QQ#
      ,[MSN]=#MSN#
      ,[Sequence]=#Sequence#
      ,[AccountState]=#AccountState#
      ,[LastUpdateUserName]=#LastUpdateUserName#
      ,[LastUpdateUserFullName]=#LastUpdateUserFullName#
      ,[LastUpdateTime]=#LastUpdateTime#
      ,[CreateUserName]=#CreateUserName#
      ,[CreateUserFullName]=#CreateUserFullName#
      ,[CreateDateTime]=#CreateDateTime#
      WHERE [UserName]=#UserName#
    </update>
    
    <!-- Select-->
    <!-- User-->
    <select id="GetUserItemByUserName" parameterClass="HashTable" resultClass="Kaiser.Models.User">
      SELECT *
      FROM SYS_User
      <dynamic prepend="where">
        <isParameterPresent>
          <isNotEmpty property="username">
            UserName =  '$username$'
          </isNotEmpty>
        </isParameterPresent>
      </dynamic>
    </select>

    <select id="GetUserBasicList"  resultClass="HashTable">
      SELECT *
      FROM SYS_User
      <dynamic prepend="where">
        <isParameterPresent>
          <isNotEmpty property="DeptID">
            deptid =  '$DeptID$'
          </isNotEmpty>
        </isParameterPresent>
      </dynamic>
    </select>



    <!-- Org-->
    <select id="GetSyncOrgTree" parameterClass="HashTable" resultClass="HashTable">
      SELECT *
      FROM SYS_Dept
      <dynamic prepend="where">
        <isParameterPresent>
          <isNotEmpty property="DeptID">
            DeptID =  '$DeptID$'
          </isNotEmpty>
        </isParameterPresent>
      </dynamic>
    </select>
    <!--Area-->
    <select id="GetAreaRootTree" parameterClass="HashTable" resultClass="HashTable">
      SELECT id,name
      FROM SYS_Area  where  parent_id is null 
    </select>
    <select id="GetAreaChildByParentId" parameterClass="HashTable" resultClass="HashTable">
      SELECT id,name
      FROM SYS_Area
      <dynamic prepend="where">
        <isParameterPresent>
          <isNotEmpty property="parentId">
            parent_id =  '$ParentId$'
          </isNotEmpty>
        </isParameterPresent>
      </dynamic>
    </select>
  </statements>
</sqlMap>